package com.ruoci.redis.response;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author yang
 **/
@Data
public class BasicResponse <T> implements Serializable {

    private Integer code;

    private String message;

    private T data;

    public BasicResponse(Integer code,String message){
        this.code = code;
        this.message = message;
    }

    public BasicResponse(Integer code,String message,T data){
        this(code,message);
        this.data = data;
    }

    public static <T> BasicResponse<T> success(){
        return new BasicResponse<>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMessage());
    }

    public static <T> BasicResponse<T> success(T data){
        return new BasicResponse<>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMessage(),data);
    }

    public static <T> BasicResponse<T> fail(){
        return new BasicResponse<>(ResponseCode.FAILURE.getCode(),ResponseCode.FAILURE.getMessage());
    }

    public static <T> BasicResponse<T> fail(Integer code,String message){
        return new BasicResponse<>(code,message);
    }
}
